package com.bot.nft.module.dc.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bot.common.pojo.CommonResult;
import com.bot.nft.module.dc.domain.bo.DcNftCertQueryBo;
import com.bot.nft.module.dc.domain.bo.DcNftCertSendBo;
import com.bot.nft.module.dc.domain.vo.DcNftCertVo;
import com.bot.nft.module.dc.service.IDcNftCertService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 藏品证书前端控制器
 * </p>
 *
 * @author zhangkaige
 * @since 2024-01-24
 */
@RestController
@RequestMapping("/cert")
public class DcNtfCertController {

    @Resource
    private IDcNftCertService nftCertService;

    @GetMapping("/{certId}/getNftCert.do")
    public CommonResult<DcNftCertVo> queryCertList(@PathVariable String certId) {
        DcNftCertVo nftCert = nftCertService.getNftCertVo(certId);
        return CommonResult.data(nftCert);
    }

    @PostMapping("/{pageNo}/{pageSize}/pageNftCert.do")
    public CommonResult<Page<DcNftCertVo>> queryCertList(@PathVariable Integer pageNo,
                                                         @PathVariable Integer pageSize,
                                                         @RequestBody DcNftCertQueryBo certQueryBo) {
        Page<DcNftCertVo> nftCertVoPage = nftCertService.pageNftCertVo(pageNo, pageSize, certQueryBo.getMbId(),
                certQueryBo.getMbPhone(), certQueryBo.getNftName(), certQueryBo.getStatus());
        return CommonResult.data(nftCertVoPage);
    }

    @PostMapping("/sendNftCert.do")
    public CommonResult<Boolean> sendNftCert(@RequestBody DcNftCertSendBo certSendBo) {
        Boolean flag = nftCertService.sendNftCert(certSendBo.getCertId(), certSendBo.getSenderId(),
                certSendBo.getReceiverId());

        return flag ? CommonResult.ok() : CommonResult.error();
    }

    @PostMapping("/receiveNftCert.do")
    public CommonResult<Boolean> receiveNftCert(@RequestBody DcNftCertSendBo certSendBo) {
        Boolean flag = nftCertService.receiveNftCert(certSendBo.getCertId(), certSendBo.getSenderId(),
                certSendBo.getReceiverId());

        return flag ? CommonResult.ok() : CommonResult.error();
    }

    @PostMapping("/cellNftCert.do")
    public CommonResult<Boolean> cellNftCert(@RequestBody @Valid DcNftCertSendBo certSendBo) {
        Boolean flag = nftCertService.sellNftCert(certSendBo.getCertId(), certSendBo.getMbId());

        return flag ? CommonResult.ok() : CommonResult.error();
    }

}
